package cate.game.rank.h;

import cate.game.rank.po.ExtraReplayRankSPO;
import cate.game.rank.po.ExtraValueRankSPO;
import cate.game.rank.po.Rank;
import cate.game.rank.vo.RankParam;
import cate.game.role.Role;

public abstract class RankExtraReplayHandler<T extends ExtraReplayRankSPO> extends RankHandler<T , Rank>{
    /**
     * 默认value大，extraValue大的排前面
     */
    public void record(Role role, long value, long extraValue, String replayUid) {
        record(role, value, extraValue, replayUid, true);
    }

    /**
     * @see ExtraValueRankSPO.Type
     */
    public void record(Role role, long value, long extraValue, String replayUid, boolean sort) {
        RankParam param = RankParam.build(role);
        long preValue = getRankValue(param,0);
        synchronized(this){
            getSPO(gameBody).record(role, value, extraValue, replayUid, sort);
            if(!sort){
                getSPO(gameBody).sort();
            }
            save();
        }
        afterRecord(preValue, param);
    }
}
